package com.example.admin.service.impl;



import com.example.admin.mapper.SupMapper;
import com.example.admin.service.SupService;
import com.example.common.result.PageBean;
import com.example.model.supplier.dto.SupplierProductDTO;
import com.example.model.supplier.pojo.Supplier;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Slf4j
@Service
public class SupServiceimpl implements SupService {

    @Autowired
    private SupMapper supMapper;


    @Transactional//保证原子性
    @Override
    public void delete(List<Integer> ids) {
        //删除关系表中的对应的id
        supMapper.DeleteAllId(ids);

    }

    @Override
    public void save(SupplierProductDTO supplierProductDTO) {
        log.info("supplier{}",supplierProductDTO);
        supMapper.save(supplierProductDTO);
    }

    @Override
    public SupplierProductDTO selectById(Integer id) {
        SupplierProductDTO supplierProductDTO = supMapper.selectById(id);
        return supplierProductDTO;
    }

    @Override
    public void updateById(SupplierProductDTO supplierProductDTO) {
        supMapper.updateById(supplierProductDTO);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String supplierName, String productName) {
        PageHelper.startPage(page, pageSize);

        List<SupplierProductDTO> list= supMapper.page(supplierName,productName);
        Page<SupplierProductDTO> p = (Page<SupplierProductDTO>) list;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
